#include "ThreadMgr.h"
#include "Threadable.h"

ThreadMgr * ThreadMgr::m_singleMgr = NULL;

std::map<int , Threadable *> ThreadMgr::threads;


ThreadMgr * ThreadMgr::getinstance()
{

    if(m_singleMgr == NULL)
    {
        m_singleMgr = new ThreadMgr();

    }
    return m_singleMgr;
}


ThreadMgr::ThreadMgr()
{


}

void ThreadMgr::svc(int id)
{

//    std::cout << "raise " << id << std::endl;

    std::map<int , Threadable *>::iterator itr = threads.find(id);

    Threadable * t_object = itr->second;

    t_object->svc();
}


void ThreadMgr::activate(int id)
{


//    std::cout << "activate " << id << std::endl;

    boost::thread t(svc, id);
   // t.join();
}



void ThreadMgr::registerThread(Threadable * tptr)
{
    int t_id = tptr->t_id;
    threads[t_id] = tptr;
}
